package com.gateway.enter.controller;

import com.gateway.enter.entity.Gate;
import com.gateway.enter.entity.Student;
import com.gateway.enter.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author KLC0422
 * @create 2021-12-26- 10:31
 */
@Controller
public class HomeController {

    @Autowired
    private StudentService studentService;

    @PostMapping("/gateWay")
    public String gate(Gate gate,Map<String, Object> map, HttpServletRequest httpServletRequest){
        Student student =(Student) httpServletRequest.getSession().getAttribute("student");
        student = studentService.getStudentByEmailAddress(student);
        if(student == null){
            map.put("msg","您还未登录");
            return "site/error";
        }
        if(student.getActive() == 0){
            map.put("msg","您还未激活，请联系管理员");
            return "site/error";
        }
        String address = student.getAddress();
        if(address==null){
            map.put("msg","您还未上传照片地址");
            return "site/home";
        }
        map.put("Address",student.getAddress());
        map.put("StudentName",gate.getStudentName());
        map.put("StudentId",gate.getStudentId());
        map.put("Region",gate.getRegion());
        return "site/gate";
    }

}
